package com.engc.common.utils;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 发送信息公共类，将信息发送给推送平台，由推送平台统一发送
 * 
 * @author Administrator
 * 
 */
public class sendMessage {
	private static Log log = LogFactory.getLog(sendMessage.class);// 日志记录器
	public static final int TypeOfSendSMS = 0;
	public static final int TypeOfSendMobile=1;
	public static final int TypeOfSendEmail = 2;
	public static final int TypeOfSendPCDiskTop = 3;

	private static sendMessage me;
	public static sendMessage getInstance(){
		if(me==null){
			me = new sendMessage();
		}
		return me;
	}
	private sendMessage(){
	}
	
	public  void send(String message, String user, int... type)  {
		try {
			Socket sk = new Socket("127.0.0.1", 9090);
			OutputStream out = sk.getOutputStream();
			if(out!=null){
				if (type.length > 0) {
					for (int i = 0; i < type.length; i++) {
						int ctype = type[i];
						String sendmessage = "SOCKET;" + ctype + ";" + user + ";"
								+ message;
						log.info(sendmessage);
						//
						out.write(sendmessage.getBytes("UTF-8"));
						out.flush();
					}
				}
			}
		} catch (Exception e1) {
			e1.printStackTrace();
		}
	}
}
